package springboot.doMain;

import lombok.Data;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * over_time_data
 */
@Data
public class OverTimeData implements Serializable {
    /**
     * 日期
     */
    private Long date;

    /**
     * 员工名称
     */
    private String name;

    /**
     * 问题数
     */
    private Integer proCnt;

    /**
     * 消息数量
     */
    private Integer msgCnt;

    /**
     * 消息加问题数量
     */
    private Integer allCnt;

    /**
     * 插入时间
     */
    private String insertDate;

    private static final long serialVersionUID = 1L;

    public static OverTimeData fill(Map<String, Object> m) {
        OverTimeData o = new OverTimeData();
        if (m.containsKey("msg_cnt")) {
            o.setMsgCnt(Integer.valueOf(m.get("msg_cnt").toString()));
        }
        if (m.containsKey("name")) {
            o.setName((String) m.get("name"));
        }
        if (m.containsKey("pro_cnt")) {
            o.setProCnt(Integer.valueOf(m.get("pro_cnt").toString()));
        }
        if (m.containsKey("all_cnt")) {
            o.setAllCnt(Integer.valueOf(m.get("all_cnt").toString()));
        }
        if (m.containsKey("insert_date")) {
            o.setInsertDate(m.get("insert_date").toString());
        }
        o.date = new Date().getTime() / 1000;
        return o;
    }

    public static List<OverTimeData> fillList(List<Map<String, Object>> s) {
        if (s == null || s.size() == 0)
            return null;
        List<OverTimeData> sqs = new ArrayList<>();
        s.forEach(stringStringMap -> sqs.add(fill(stringStringMap)));
        return sqs;
    }


    @Override
    public boolean equals(Object that) {
        if (this == that) {
            return true;
        }
        if (that == null) {
            return false;
        }
        if (getClass() != that.getClass()) {
            return false;
        }
        OverTimeData other = (OverTimeData) that;
        return (this.getDate() == null ? other.getDate() == null : this.getDate().equals(other.getDate()))
                && (this.getName() == null ? other.getName() == null : this.getName().equals(other.getName()))
                && (this.getProCnt() == null ? other.getProCnt() == null : this.getProCnt().equals(other.getProCnt()))
                && (this.getMsgCnt() == null ? other.getMsgCnt() == null : this.getMsgCnt().equals(other.getMsgCnt()))
                && (this.getAllCnt() == null ? other.getAllCnt() == null : this.getAllCnt().equals(other.getAllCnt()))
                && (this.getInsertDate() == null ? other.getInsertDate() == null : this.getInsertDate().equals(other.getInsertDate()));
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + ((getDate() == null) ? 0 : getDate().hashCode());
        result = prime * result + ((getName() == null) ? 0 : getName().hashCode());
        result = prime * result + ((getProCnt() == null) ? 0 : getProCnt().hashCode());
        result = prime * result + ((getMsgCnt() == null) ? 0 : getMsgCnt().hashCode());
        result = prime * result + ((getAllCnt() == null) ? 0 : getAllCnt().hashCode());
        result = prime * result + ((getInsertDate() == null) ? 0 : getInsertDate().hashCode());
        return result;
    }
}
